package org.lalib.entity.object.variable.value;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.reflect.TypeToken;

public class ListVariableBean {

	private int removeId = 0;

	private List<ListValue> listValues = new ArrayList<>();

	public void addValue() {
		listValues.add(new ListValue());
	}

	public void removeValue() {
		listValues.remove(removeId);
	}

	public String getValueAsString() {
		return new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(getListValues());
	}

	@SuppressWarnings("unchecked")
	public void getValueFromJson(String value) {
		setListValues(((List<ListValue>) new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
				.fromJson(value, new TypeToken<List<ListValue>>() {
				}.getType())));
	}

	public class ListValue {

		@Expose
		private String value;

		public ListValue() {
			setValue("");
		}

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}
	}

	public List<ListValue> getListValues() {
		return listValues;
	}

	public void setListValues(List<ListValue> listValues) {
		this.listValues = listValues;
	}

	public int getRemoveId() {
		return removeId;
	}

	public void setRemoveId(int removeId) {
		this.removeId = removeId;
	}
}
